define([
    'jquery',
    'underscore',
    'backbone',
    'text!admin/user/edit.html',
    'js/myApiAmd',
    'js/myUtilsAmd'
], function ($, _, Backbone, tpl, myApi, myUtils) {
    var View = Backbone.View.extend({

        initialize: function () {
            this.tmpl = _.template(tpl);
        },

        events: {
            "submit #editUser": "doEdit"
        },

        doEdit: function () {
            console.log('TODO doEdit');
            return false;
        },

        onRender: function (qs, callback) {
            var that = this;
            qs = myUtils.parseQueryString(qs);
            var id = qs.id;
            myApi.getAdminOne(id, function (err, res) {
                console.log(res);
                res = JSON.parse(res);
                $(that.el).html(that.tmpl({admin: res.doc}));
                callback(that);
            });
        },

        onReshow: function (qs, callback, forceReload) {
            $(this.el).show();
        },

        hide: function () {
            $(this.el).hide();
        },

        remove: function () {
            $(this.el).remove();
        }

    });

    return View;
});